package fr.upstlse.glre.client.administration.utilisateurs.action;

import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.DataList;

import fr.upstlse.glre.client.administration.utilisateurs.ModificationPanel;
import fr.upstlse.glre.client.administration.utilisateurs.ModificationWindow;
import fr.upstlse.glre.client.vo.user.UserVOGWT;
import fr.upstlse.glre.client.widgets.modelData.UserModelData;

public class UserSelectionAction implements Listener<ComponentEvent> {

	private ContentPanel modificationPanel;
	private DataList modificationList;
	private UserVOGWT user;
	
	public UserSelectionAction() {
		modificationPanel = ModificationPanel.getInstance().getModificationPanel();
		modificationList = ModificationPanel.getInstance().getModificationList();
	}
	
	public void handleEvent(ComponentEvent be) {
		if(modificationList.getSelectedItem() != null) {
			ModelData lModelData = modificationList.getSelectedItem().getModel();
			if(lModelData instanceof UserModelData) {
				UserModelData lUserModelData = new UserModelData(lModelData);
				user = lUserModelData.toUserVOGWT();
				ModificationWindow.closeCurrentWindow();
				ModificationWindow lModificationWindow = ModificationWindow.getInstance(user);
				lModificationWindow.show();
			}
		}
		modificationPanel.layout();
	}

}
